<template>
  <div class="content-box">
    <nav-title title="转正审批" :routerLink="routerLink" />
    <div class="regulations-box">
      <div class="title">基本信息</div>
      <simple-line title="员工ID" v-bind:value="baseInfo.emplid" />
      <simple-line title="姓名" v-bind:value="baseInfo.nameDisplay" />
      <simple-line title="部门" v-bind:value="baseInfo.deptName" />
      <simple-line title="岗位" v-bind:value="baseInfo.jobcodeDescr" />
      <simple-line title="职等" v-bind:value="baseInfo.cJobLevel" />
      <simple-line title="导师" v-bind:value="baseInfo.cEmplidName" />
      <simple-line title="入职日期" v-bind:value="baseInfo.cWklifBgnDt2" />
      <simple-line title="联系电话" v-bind:value="baseInfo.phone" />
      <simple-line title="申请日期" v-bind:value="baseInfo.cWfAppDt" />
      <simple-line title="岗位性质" v-bind:value="baseInfo.cJobType" />
    </div>
    <div class="regulations-box">
      <div class="title">详细信息</div>
      <simple-line title="所属部门总经理" v-bind:value="baseInfo.deptManager" />
      <simple-line title="所属事业部总经理" v-bind:value="baseInfo.unitManager" />
      <simple-line title="毕业学校" v-bind:value="baseInfo.cSchool" />
      <simple-line title="毕业时间" v-bind:value="baseInfo.cGraEndDt" />
      <simple-line title="专业" v-bind:value="baseInfo.cMajor" />
      <simple-line title="学历" v-bind:value="baseInfo.highestEducLvlValue" />
      <simple-line title="试用期考核期" v-bind:value="baseInfo.cWfPrcNum" v-if="displayVal['cWfPrcNum']" />
      <simple-line title="360测评成绩" v-bind:value="baseInfo.cAssmRslt" v-if="displayVal['cAssmRslt']" />
    </div>
    <!-- <div class="regulations-box">
      <div class="title">转正人员</div>
      <label class="chose_radio" for="gRadio1"><input type="radio" id="gRadio1" name="groupType" v-bind:checked="baseInfo.cGroupType==1" /><i></i>
        <div>集团公司其他</div>
      </label>
      <label class="chose_radio" for="gRadio2"><input type="radio" id="gRadio2" name="groupType" v-bind:checked="baseInfo.cGroupType==2" /><i></i>
        <div>事业部>=8职等、管委会、一级公司品质、财务、审计、供应链、成本</div>
      </label>
      <label class="chose_radio" for="gRadio3"><input type="radio" id="gRadio3" name="groupType" v-bind:checked="baseInfo.cGroupType==3" /><i></i>
        <div>事总；集团公司>=7职等、职能部第一负责人、管委会</div>
      </label>
    </div> -->

    <div class="regulations-box">
      <div class="title">流程信息</div>
      <edit-option-line label="转正类型" :important="true" :vals="typeList" v-if="displayVal['cPrcType']" :readonly="!editVal['cPrcType']"
        :showValue="baseInfo.cPrcTypeValue" :boldtitle="true" v-model="baseInfo.cPrcType"></edit-option-line>
      <edit-option-line label="转正人员" :important="true" v-if="displayVal['cGroupType']" :readonly="!editVal['cGroupType']" :vals="groupTypeList" :showValue="baseInfo.cGroupTypeValue"
        :boldtitle="true" v-model="baseInfo.cGroupType"></edit-option-line>
      <edit-date-line label="转正日期" :important="true" v-if="displayVal['cPrcDt']" :readonly="!editVal['cPrcDt']"
        :boldtitle="true" v-model="baseInfo.cPrcDt"></edit-date-line>
      <file-line label="附件" :fileitems="baseInfo.wfFiles" :boldtitle="true" />
    </div>
    <div class="regulations-box">
      <div v-show="displayVal['cDefect']">
        <!-- <div class="info-label">直属领导评价</div> -->
        <p class="info-cell clearfix">
          <label class="info-label-title">直属领导评估意见</label>
        </p>
        <div class="info-label-text">
          <textarea placeholder="请在这里输入..." rows="5" v-model="baseInfo.cDefect" :readonly="!editVal['cDefect']"></textarea>
        </div>
      </div>
      <div v-show="displayVal['cAchievement']">
        <!-- <div class="info-label">人力资源评价</div> -->
        <p class="info-cell clearfix">
          <label class="info-label-title">取得的成绩</label>
        </p>
        <div class="info-label-text">
          <textarea placeholder="请在这里输入..." rows="5" v-model="baseInfo.cAchievement" :readonly="!editVal['cAchievement']"></textarea>
        </div>
      </div>
    </div>

    <div class="regulations-box">
      <div class="title">分权引用</div>
      <fqyy-line :editting="false" :fqyyFlag="fqyyInfo.cFqyyFlag" :noFqyySum="fqyyInfo.noFqyySum" :noFqyyRatio="fqyyInfo.noFqyyRatio"
        :fqyyMsg="fqyyInfo.cFqyyDetail" ref="fqyy"></fqyy-line>
    </div>


    <!-- 流程图 -->
    <div class="regulations-box">
      <div class="title">流程图</div>
      <v-flow-charts :transNum="cTransactionNbr" :loginOprid="loginOprid"></v-flow-charts>
    </div>

    <!-- 审批意见 -->
    <div class="regulations-box" v-if="approved == '0'&&baseInfo.cStepType!='C' && baseInfo.cIsChuanyue != 'Y'">
      <div class="info-label">审批意见</div>
      <div class="info-label-text">
        <textarea placeholder="请在这里输入..." rows="5" v-model="cComments"></textarea>
      </div>
    </div>

    <div style="height: 50px"></div>
    <!-- 底部按钮 -->
    <div v-if="approved == '0'">
      <operation-btn :cApprovalSw="baseInfo.cApprovalSw" :cDenySw="baseInfo.cDenySw" :cPushbackAllSw="baseInfo.cPushbackAllSw"
        :cAddSw="baseInfo.cAddSw" :cTransactionNbr="baseInfo.cTransactionNbr" :cWfType="baseInfo.cWfType" :cReadSw="baseInfo.cIsChuanyue"
        :cStepType="baseInfo.cStepType" :cComments="cComments" :approveBizType="'formal'" :getBizParams="getBizParams"
        :validAgree="validAgree"></operation-btn>
    </div>
  </div>
</template>

<script>
  import { dateFormat, Selector, Datetime, Group, PopupPicker, PopupRadio, } from "vux";
import {
  getFormal,
  getDicItem,
  getPrcType,
  getJobDicItem,
  getFqyyInfo,
  getFormalApprove,
  saveFormalInfo
} from "../../api/api";
import fqyyLine from "../../components/basic/FqyyLine"
import { json2For} from "../../util/http";
import vBaseInfo from "../formalStaff/baseInfo";
import vDetailInfo from "../formalStaff/detailInfo";
import FileLine from '../../components/basic/FileLine'
import EditDateLine from '../../components/basic/EditDateLine'
import EditOptionLine from '../../components/basic/EditOptionLine'
import vFlowCharts from "../formalStaff/common/flowChart";
import SimpleLine from '../../components/basic/SimpleLine'
import CommonUtil from '../../components/basic/util'
import operationBtn from "./common/operationBtn";

export default {
  name: "guide-to",
  components: {
    Group,
    Selector,
    Datetime,
    PopupPicker,
    vBaseInfo,
    vDetailInfo,
    PopupRadio,
    vFlowCharts,
    EditDateLine,
    EditOptionLine,
    SimpleLine,
    operationBtn,
    FileLine,
    fqyyLine
  },
  created() {
  },
  mounted() {
    CommonUtil.tryLogin(this).then(()=>{
      this.approved = this.$route.query.approved;
      if (this.$route.query.approved == "1") {
        this.routerLink = "/todoList/done";
      } else {
        this.routerLink = "/todoList/todo";
      }
      this.cTransactionNbr = this.$route.query.cTransactionNbr;
      this.stepNbr = this.$route.query.stepNbr;
      this.loginOprid = this.$route.query.token;
      //转正审批信息
      this.getFormalInfo();
      this.getCertType();
      getFqyyInfo({'cTransactionNbr':this.cTransactionNbr,'processType':'formal'}).then(res => {
                this.fqyyInfo = res.retData;
            })

      CommonUtil.loadDic(this.groupTypeList, 'C_GROUP_TYPE', "xlatlongname","fieldvalue")
    })
  },
  data() {
    return {
      fqyyInfo:{
        fqyyFlag:'',
        fqyyDetail:''
      },
      approved: '0',
      routerLink: "/todoList/todo",
      baseInfo: {},
      cComments: "",
      displayVal: {},
      editVal: {},
      cTransactionNbr : this.$route.query.cTransactionNbr,
      typeList: [],
      groupTypeList:[]
    };
  },
  methods: {
    validAgree(){
       if(!this.baseInfo.cGroupType) {
         this.$vux.alert.show({
           title: "警告",
           content: "请选择转正人员"
         });
         return false;
       }
       saveFormalInfo(this.baseInfo).then(res => {
        if (res && res.retCode === "000000") {

          }else{
            this.$vux.alert.show({
              title: "警告",
              content: "网络异常，请稍后重试"
            });
            return false;
          }
       })
       return true;
    },
    getCertType() {
      //转正类型字典
      getPrcType()
        .then(res => {
          this.typeList = [];
          if (res && res.retCode === "000000") {
            for (let i = 0; i < res.retData.length; i++) {
              this.typeList.push({
                value: res.retData[i].descr,
                key: res.retData[i].cPrcType
              });
            }
          }
        })
        .catch(res => {});
    },
    getFormalInfo() {
      this.$vux.loading.show();
      let params = {
        cTransactionNbr: this.cTransactionNbr,
        stepNbr: this.stepNbr,
        loginOprid: this.loginOprid
      };
      getFormal(params)
        .then(res => {
          this.$vux.loading.hide();
          if (res && res.retCode === "000000") {

            this.baseInfo = res.retData;
            CommonUtil.updateFileUrl(this.baseInfo.wfFiles);
            //权限及展示控制
            let auths = res.retData.authFileds;
            for(var i=0;i<auths.length;i++) {
              this.displayVal[auths[i].fieldKey] = auths[i].isDisplay
              this.editVal[auths[i].fieldKey] = auths[i].isEdit
            }
            this.baseInfo.cWklifBgnDt2 = dateFormat(new Date(res.retData.cWklifBgnDt2), "YYYY-MM-DD");
            this.baseInfo.cPrcDt = dateFormat(new Date(res.retData.cPrcDt), "YYYY-MM-DD");
            this.baseInfo.birthdate = dateFormat(new Date(res.retData.birthdate), "YYYY-MM-DD");
            this.baseInfo.hireDt = dateFormat(new Date(res.retData.hireDt), "YYYY-MM-DD");
            this.baseInfo.cWfAppDt = dateFormat(new Date(res.retData.cWfAppDt), "YYYY-MM-DD");
          } else {
            this.$vux.alert.show({
              title: "提示",
              content: res.retMsg
            });
          }
        })
        .catch(res => {
          console.error(res)
          this.$vux.loading.hide();
          this.$vux.alert.show({
            title: "警告",
            content: "网络异常，请稍后重试"
          });
        });
    },
    getBizParams(){
      var _this = this;
      var params = {};

      console.error(_this.editVal)
      Object.keys(_this.editVal).forEach(function(key){
        if(key && _this.editVal[key]) {
          params[key] = _this.baseInfo[key]
        }
      });
      return params;
    }
  }
};
</script>

<style type="text/scss" lang="scss">
  @import "../../styles/staff.scss";
.chose_radio{
  text-align: left;
  margin: 4px 20px;
  display: block;

  >input[type="radio"]{
    display: none;
    &:checked{
      & + i{
        border: 5px solid #1CAAFE;
      }
    }
  }
  >i {
    display: block;
    width: 20px;
    height: 20px;
    border: 1px solid #aaa;
    border-radius: 20px;
    margin-right: 10px;
    float: left;
  }
  >div{
    line-height: 20px;
    padding-left: 30px;
    margin: 8px 0;
  }
}
.reject-main {
  position: relative;
  .reject-group {
    position: absolute;
    top: -80px;
    left: 0px;
    button {
      margin-bottom: 1px;
    }
  }
}
.slide-fade-enter-active {
  transition: all 0.1s ease;
}
.slide-fade-leave-active {
  transition: all 0.2s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter, .slide-fade-leave-to
/* .slide-fade-leave-active for below version 2.1.8 */ {
  transform: translateY(10px);
  opacity: 0;
}
</style>
